package com.example.jasonrpc.server.simple;

import com.example.jasonrpc.common.ReflectionUtils;
import com.example.jasonrpc.server.RpcServerAbstract;

public class RpcServer extends RpcServerAbstract {

    public RpcServer(RpcServerConfig config) {
        //网络模块
        this.net = ReflectionUtils.newInstance(config.getTransportClass());
        this.net.init(config.getPort(), this.handler);
        this.encoder = ReflectionUtils.newInstance(config.getEncoderClass());
        this.decoder = ReflectionUtils.newInstance(config.getDecoderClass());
        //服务
        this.manager = new ServiceManager();
        this.invoker = new ServiceInvoker();
    }

    public RpcServer(int port) {
        this(new RpcServerConfig(port));
    }

    public void start() {
        net.start();
    }

    public void stop() {
        net.stop();
    }
}
